package com.supreme.simpleserver.aspect;

import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
@Slf4j
public class MybatisLogAspect {

    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    @Pointcut("execution(public * com.supreme.commonmybatis.mapper.mybatis..*.*(..))")
    public void PointCut(){

    }

    @Around("PointCut()")
    public Object aroundMethod(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
        final Method method = methodSignature.getMethod();
        log.info("method: {}", method.getName());
        final Object proceed = proceedingJoinPoint.proceed();
        return proceed;
    }
}
